package com.danan.realtime.util;

import redis.clients.jedis.*;

/**
 * @author NanHuang
 * @Date 2023/1/26
 */
public class RedisUtil {

    private static JedisPool jedisPool;

    static {
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxTotal(10);
        jedisPoolConfig.setMaxIdle(5);
        jedisPoolConfig.setMinIdle(5);
        jedisPoolConfig.setBlockWhenExhausted(true);
        jedisPoolConfig.setMaxWaitMillis(2000);
        jedisPoolConfig.setTestOnBorrow(true);
        jedisPool = new JedisPool(jedisPoolConfig, ResourceBundleUtil.getProperty("redis.hostname"), Integer.parseInt(ResourceBundleUtil.getProperty("redis.port")));
    }
    public static Jedis getJedis(){
        Jedis jedis = jedisPool.getResource();
        jedis.select(7);
        return jedis;
    }
}
